#include <stdio.h>
#include <stdlib.h>

/**
 * 
 * 顺序栈及其基本操作 
 **/
 
//入栈
int push(int* arr,int top,int elem);  

//出栈
int pop(int* arr,int top); 

int main()
{
	int a[100];
	int top=-1;
    top=push(a, top, 1);
    top=push(a, top, 2);
    top=push(a, top, 3);
    top=push(a, top, 4);
    top=pop(a, top);
    top=pop(a, top);
    top=pop(a, top);
    top=pop(a, top);
    top=pop(a, top);
	system("pause");
	return 0;
}

int push(int* arr,int top,int elem)
{
	arr[++top]=elem;
	return top;
}

int pop(int* arr,int top)
{
	//判断是栈中是否有个元素 
	if(top==-1)
	{
		printf("空栈\n");
		return -1;
	} 
	
	printf("弹栈元素:%d\n",arr[top--]);
	return top;
}
